import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.*;
public class AdminTest {
    private Admin admin;
    private User testUser;
    private Movie testMovie;
    @BeforeEach
    void setUp() {
        // 创建管理员对象
        admin = new Admin("admin001", "adminName", "adminPass", new Date(), "1234567890");
        // 创建测试用户
        testUser = new FrontDesk("user001", "testUser", "userPass",new Date(),"12345678901");
        // 创建测试电影
        testMovie = new Movie("movie001", "Test Movie", "Test Director", "Test Actors","Test Intro",100,7.5);
    }
    // 测试根据用户名查询用户方法
    @Test
    void testQueryUserByUsername() {
        User testUser = new FrontDesk("uesr002","testUser","userPassword",new Date(),"12345678900");
        testUser.setPhone("1234567891");
        admin.addUser(testUser);
        User result = admin.queryUserByPhone("1234567891");
        assertEquals(testUser, result);
        User notFound = admin.queryUserByPhone("1234567892");
        assertNull(notFound);
    }
    // 测试根据手机号查询用户方法
    @Test
    void testQueryUserByPhone() {
        User testUser = new FrontDesk("uesr002","testUser","userPassword",new Date(),"12345678900");
        testUser.setPhone("1234567891");
        admin.addUser(testUser);
        User result = admin.queryUserByPhone("1234567891");
        assertEquals(testUser, result);
        User notFound = admin.queryUserByPhone("1234567892");
        assertNull(notFound);
    }
    // 测试修改管理员密码方法
    @Test
    void testModifyAdminPassword() {
        String oldPassword = admin.getPassword();
        admin.modifyAdminPassword(admin, "newAdminPass");
        assertNotEquals(oldPassword, admin.getPassword());
        assertEquals("newAdminPass", admin.getPassword());
    }
    // 测试重置用户密码方法
    @Test
    void testResetUserPassword() {
        String oldPassword = testUser.getPassword();
        admin.resetUserPassword(testUser, "newUserPass");
        assertNotEquals(oldPassword, testUser.getPassword());
        assertEquals("newUserPass", testUser.getPassword());
    }
    // 测试添加放映场次方法
    @Test
    void testAddScreening() {
        Screening testScreening = new Screening("screen001", testMovie,"1号厅", new Date(),50);
        int beforeSize = admin.getScreenings().size();
        admin.addScreening(testScreening);
        assertEquals(beforeSize + 1, admin.getScreenings().size());
    }
    // 测试列出所有用户方法
    @Test
    void testListAllUsers() {
        admin.addUser(testUser);
        assertEquals(1, admin.listAllUsers().size());
    }
    // 测试删除用户方法
    @Test
    void testDeleteUser() {
        admin.addUser(testUser);
        admin.deleteUser(testUser);
        assertFalse(admin.listAllUsers().contains(testUser));
    }
    // 测试修改用户信息方法
    @Test
    void testModifyUserInfo() {
        admin.addUser(testUser);
        admin.modifyUserInfo(testUser, UserType.MANAGER, "1234567892");
        assertEquals(UserType.MANAGER, testUser.getUserType());
        assertEquals("1234567892", testUser.getPhone());
    }
    // 测试列出所有电影信息方法
    @Test
    void testListAllMovies() {
        admin.addMovie(testMovie);
        admin.listAllMovies();
    }
    // 测试根据电影 ID 查找电影方法
    @Test
    void testFindMovieById() {
        admin.addMovie(testMovie);
        Movie result = admin.findMovieById("movie001");
        assertEquals(testMovie, result);
        Movie notFound = admin.findMovieById("movie002");
        assertNull(notFound);
    }
    // 测试登录方法
    @Test
    void testLogin() {
        admin.login();
    }
    // 测试登出方法
    @Test
    void testLogout() {
        admin.logout();
    }
    // 测试密码管理方法
    @Test
    void testManagePassword() {
        admin.managePassword();
    }
}
